using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Utilities;

namespace BizTalk.BuildGenerator.Tasks.BAM
{
    /// <summary>
    /// This is a base class for tasks which will use bttdeploy.exe
    /// </summary>
    public class BaseBTTDeployTask : Task
    {
        private string _BttDeployPath = @"c:\Program Files\Microsoft BizTalk Server 2009\Tracking\bttdeploy";
        private string _ManagementDb;

        /// <summary>
        /// Optional parameter to specify the management db in the format /mgdb <server name[,port]>\<database name>
        /// </summary>
        public string ManagementDb
        {
            get { return _ManagementDb; }
            set { _ManagementDb = value; }
        }

        /// <summary>
        /// The path to BTTDeploy.exe, this is optional
        /// </summary>
        public string BttDeployPath
        {
            get { return _BttDeployPath; }
            set { _BttDeployPath = value; }
        }
        /// <summary>
        /// Executes BTTDeploy with a set of arguments
        /// </summary>
        /// <param name="arguments"></param>
        protected bool ExecuteBTTDeploy(string arguments)
        {
            Microsoft.Build.Tasks.Exec exec = new Microsoft.Build.Tasks.Exec();
            exec.BuildEngine = this.BuildEngine;
            exec.Command = "\"" + this._BttDeployPath + "\" " + arguments;

            if (!string.IsNullOrEmpty(this._ManagementDb))
                exec.Command += string.Format(" /mgdb {0}", this._ManagementDb);            

            return exec.Execute();            
        }
        /// <summary>
        /// Execute method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
